<template>
  <el-container class="home">
    <el-header>
      <div class="logo">
        <img src="../assets/avator.png">
        <div>Crayon滴管理系统</div>
      </div>
      <el-button type="info" @click='LogOut'>退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="is_collapse?'64px':'240px'">
          <div class="collapse" @click="is_collapse=!is_collapse">|||</div>
          <el-menu
            :default-active="active_path"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            background-color="#323845"
            text-color="#fff"
            active-text-color="#4198f8"
            unique-opened
            :collapse="is_collapse"
            :collapse-transition='false'
            router
            >
            <el-submenu :index="'/'+item.path" v-for="item in menu_list" :key="item.id">
              <template slot="title">
                <i :class="icon_list[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
                <el-menu-item @click="SaveActivePath('/'+subitem.path)" :index="'/'+subitem.path" v-for='subitem in item.children' :key="subitem.id">
                  <i class="el-icon-menu"></i>
                  <span>{{subitem.authName}}</span>
                </el-menu-item>
            </el-submenu>
          </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default{
    data(){
      return {
        menu_list:[],
        icon_list:{
          '125':'iconfont iconusers',
          '103':'iconfont icontijikongjian',
          '101':'iconfont iconshangpin',
          '102':'iconfont icondanju',
          '145':'iconfont iconpanhebaobiao'
        },
        is_collapse:false,
        active_path:''
      }
    },
    created(){
      this.getMenuList()
      this.active_path=window.sessionStorage.getItem('active_path')
      // console.log(this.active_path);
    },
    methods:{
      LogOut(){
        window.sessionStorage.clear()
        this.$router.push('/login')
      },
      async getMenuList(){
        const res =await this.$http.get('menus')
        // console.log(res);
        if(res.data.meta.status!==200) return this.$message(res.data.meta.msg)
        this.menu_list=res.data.data
      },
      SaveActivePath(path){
        window.sessionStorage.setItem('active_path',path)
        this.active_path=path
      },
      handleOpen(){
        console.log('open');
      },
      handleClose(){
        console.log('close');
      }
    }
  }
</script>

<style lang="less">
.home{
  height: 100%;
  .el-header{
    background-color: #373e41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 25px;
    font-weight: bold;
    .logo{
      display: flex;
      align-items: center;
      img{
        width: 40px;
        height: 40px;
        margin-right: 20px;
      }
    }
  }
  .el-container{
    .el-aside{
      background-color: #373e41;
      .collapse{
        background-color: #495264;
        color: #fff;
        text-align: center;
        letter-spacing: 0.3em;
        cursor: pointer;
        line-height: 30px;
      }
      .el-menu{
        border-right:none;
        i{
          margin-right: 15px;
        }
      }
    }
    .el-main{
      background-color: #ecf0f4;
    }
  }
}
</style>